let isProduction = process.env.NODE_ENV == 'production';

//cdn不打包
const externals = {
	vue: "Vue",
	"vue-router": "VueRouter",
	vuex: "Vuex",
	axios: "axios",
	vant: 'vant'
};

// 首页cdn加载
const cdn = {
	css: [
		"https://cdnjs.cloudflare.com/ajax/libs/vant/2.12.38/index.min.css"
	],
	js: [
		"https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js",
		"https://cdnjs.cloudflare.com/ajax/libs/vue-router/3.2.0/vue-router.min.js",
		"https://cdnjs.cloudflare.com/ajax/libs/axios/0.25.0/axios.min.js",
		"https://cdnjs.cloudflare.com/ajax/libs/vant/2.12.38/vant.min.js",
		"https://cdnjs.cloudflare.com/ajax/libs/vuex/3.2.0/vuex.min.js"
	]
};



module.exports = {
	publicPath: './',
	devServer: {
		proxy: {
			'/v1': {    //将www.exaple.com印射为/apis
				target: 'https://www.lingdaoyi.net:8393/stock-server',
				changeOrigin: true
			}
		}
	},
	css: {
		loaderOptions: {
			postcss: {
				plugins: [
					require('postcss-px2rem')({
						remUnit: 37.5    //设计图 37.5 = 375/10
					})
				]
			}
		}
	},
	productionSourceMap: !isProduction,
	//线上打包使用cdn加载
	configureWebpack: {
		externals: isProduction ? externals : {}
	},
	chainWebpack: config => {
		if (isProduction) {
			config.plugin('html').tap(args => {
				args[0].cdn = cdn;
				return args;
			})
		}
	}
}
